<template>
	<view>
		<!-- 广告 -->
		<view class="banner">
			<swiper class="myswiper" autoplay="true" interval="5000" duration="500">
				<swiper-item  class="myswiper-item" v-for="(item,index) in myBannerList" :key="index">
					<image :src="item.icon" class="swiper-item-img"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 广告 -->
		<view class="container">
			<!-- 会员  -->
			<view class="members">
				<!-- 大雪人会员 -->
				<view class="members-snow">
					<view class="members-snow-back">
						<image class="members-snow-img" src="http://www.itlaobing.com/ice/other/wawa.png"></image>
					</view>
					<!-- 已授权登录 -->
					<view class="members-snow-text" v-if="cid!=0">
						<view>
							<view class="members-snow-text-title">甜蜜雪人会员</view>
							<view class="members-snow-text-content">再升1级可享[攒币加速]等9项权益</view>
						</view>
						<view>
							<view class="members-snow-text-title" style="text-align: center;">1832</view>
							<view class="members-snow-text-content">雪王币</view>
						</view>
						<view>
							<view class="members-snow-text-title" style="text-align: center;">0</view>
							<view class="members-snow-text-content">优惠卷</view>
						</view>
					</view>
					<!-- 已授权登录 -->

					<!-- 未授权登录 -->
					<view class="members-snow-text" v-else>
						<view>
							<view class="members-snow-text-title">尊敬的用户</view>
							<view class="members-snow-text-content">会员可享【闲时优惠】等多项权益</view>
						</view>
						<view>
							<button class="btn_login" @click="openpopup">授权登录</button>
						</view>
					</view>
					<!-- 未授权登录 -->
				</view>
				<!-- 大雪人会员 -->

			</view>
			<!-- 会员  -->

			<!-- 下单链接 -->
			<view class="placeorder">
				<view class="placeorder-kong placeorder-me" @click="openShops(1)">
					<view class="placeorder-kong-title">自取</view>
					<view class="placeorder-kong-content">下单免排队</view>
				</view>
				<view class="placeorder-kong placeorder-takeout" @click="openShops(2)">
					<view class="placeorder-kong-title">外卖</view>
					<view class="placeorder-kong-content">甜蜜送到家</view>
				</view>
			</view>
			<!-- 下单链接 -->

			<!-- 底部广告 -->
			<view class="bottombanner">
				<view class="bottombanner-item item1">今天喝点啥</view>
				<view class="bottombanner-item item2">福利合集</view>
				<view class="bottombanner-item item3">0元兑换</view>
			</view>
			<!-- 底部广告 -->
		</view>
	</view>
	<!-- 普通弹窗 开始-->
	<view>
		<uni-popup ref="popup" type="center">
			<view class="popup-content">
				<!-- 操作按钮开始 -->
				<view class="controller">
					<view class="btn" @click="closepopup">
						<uni-icons type="closeempty" size="20" color="#FFFFFF"></uni-icons>
					</view>
				</view>
				<!-- 操作按钮结束 -->
				 <view :class="isShow?'myRed':'myGray'">{{showTelMessage}}：</view>
				<input type="text" v-model="mytel" class="mytel" @blur="mylogin" @keyup.enter="mylogin"/>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	// import Banner from "@/components/banner/banner.vue"
	export default {
		components: {
			// Banner
		},
		data() {
			return {
				cid: getApp().globalData.cid,
				mytel: '',
				showTelMessage:'请输入手机号码',
				isShow:false,
				myBannerList:[
					{icon:'https://photo.16pic.com/00/51/53/16pic_5153329_b.jpg'},
					{icon:'https://picb2.photophoto.cn/29/061/29061262_1.jpg'}
					
				]
			}
		},
		methods: {
			openShops(takeout) {
				uni.reLaunch({
					url: "../shops/shops?takeout=" + takeout
				})
			},
			mylogin() {
				if(this.ckphone()){
					uni.setStorageSync('authentication',this.mytel)
					this.cid = this.mytel
					this.$refs.popup.close()
				}
			},
			openpopup(){
				this.$refs.popup.open('center')
			},
			//关闭商品信息窗口
			closepopup() {
				this.$refs.popup.close()
			},
			ckphone() {
				// 不做为空验证，做有效性验证
				if (this.mytel.trim() != '') {
					let pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
					if (pattern.exec(this.mytel.trim())) {
						this.showTelMessage = '请输入手机号码'
						return true
					} else {
						this.showTelMessage = '请输入有效的电话号码'
						this.isShow=true
						return false
					}
				} else {
					this.showTelMessage = '请输入手机号码'
					return true
				}
			},
			//登录
			login() {
				let _this = this;
				// 获取登录用户code
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log('res：', res)
						if (res.code) {
							_this.wxcode = res.code
							_this.getUserProfile()
						} else {
							uni.showToast({
								title: '微信登录失败！',
								duration: 2000
							});
						}
					},
				});
			},
			//登录授权
			getUserProfile() {
				var _this = this;
				uni.getUserProfile({
					desc: '登录',
					provider: 'weixin',
					success: (info) => {
						console.log('info：', info)
						this.userInfo = info
						try {
							uni.showLoading({
								title: '登录中...'
							});
							//请求后台，成功并隐藏加载
							uni.hideLoading({})
						} catch (e) {
							uni.showToast({
								title: "微信登录失败",
								icon: "none"
							});
						}
					},
					fail: (res) => {
						console.log("fail:" + res)
						uni.showToast({
							title: "您已取消授权",
							icon: "none"
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.myswiper{
		width: 100%;
		height: 45vh;
		
		.myswiper-item{
			display: block;
			width:100%;
			height: 100%;
			
			.swiper-item-img{
				width: 100%;
				height: 100%;
			}
		}
	}
	.popup-content {
		background-color: #FFFFFF;
		width: 92vw;
		height: auto;
		border-radius: 20rpx;
		overflow: hidden;
		padding: 30rpx;
		box-sizing: border-box;
		position: relative;
		z-index: 70;
		font-size: 28rpx;
		
		.myRed{
			color: red;
		}
		.myGray{
			color: #555555;
		}
		
		.mytel{
			width: 95%;
			height: 70rpx;
			border: 1px solid #AAAAAA;
			border-radius: 10rpx;
			box-sizing: border-box;
			padding-left: 20rpx;
			margin: 20rpx 0;
		}
		
		.controller {
			position: absolute;
			top: 20rpx;
			right: -20rpx;
			width: 110rpx;
			height: 50rpx;
			display: flex;
			justify-content: space-between;
		
			.btn {
				width: 50rpx;
				height: 50rpx;
				border-radius: 25rpx;
				background-color: #CCCCCC;
				color: #FFFFFF;
				text-align: center;
				line-height: 50rpx;
				font-size: 30rpx;
				z-index: 100;
			}
		}
	}

	.banner {
		width: 100vw;
		height: 45vh;
		border-bottom-left-radius: 16rpx;
		border-bottom-right-radius: 16rpx;
		overflow: hidden;
	}

	.container {
		width: 95vw;
		margin: 0 auto;
	}

	.members {
		width: 100%;
		height: 130rpx;
		position: relative;


		.members-snow {
			width: 100%;
			height: 150rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			position: absolute;
			top: -50rpx;
			box-shadow: 2px 2px 5px #CCCCCC;
			display: flex;
			padding: 30rpx 20rpx;
			box-sizing: border-box;
			justify-content: space-around;
			z-index: 10;

			.members-snow-back {
				width: 80rpx;
				height: 80rpx;
				background-color: #FFF2F1;
				margin-top: 10rpx;
				border-radius: 40rpx;
				box-shadow: 2px 2px 5px #EEEEEE;
				line-height: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				.members-snow-img {
					width: 50rpx;
					height: 60rpx;
				}
			}

			.members-snow-text {
				width: 86%;
				display: flex;
				justify-content: space-evenly;

				.members-snow-text-title {
					font-size: 31rpx;
					font-weight: bold;
				}

				.members-snow-text-content {
					font-size: 24rpx;
					color: #AAAAAA;
					padding-top: 18rpx;
				}

				.btn_login {
					// width: 160rpx;
					height: 75rpx;
					background-color: #E50014;
					color: #FFFFFF;
					font-weight: bold;
					font-size: 30rpx;
				}
			}
		}
	}

	.placeorder {
		width: 100%;
		height: 340rpx;
		display: flex;
		justify-content: space-between;

		.placeorder-kong {
			width: 49%;
			height: 100%;
			border-radius: 20rpx;
		}

		.placeorder-me {
			background-image: url(https://img.tukuppt.com/photo-big/00/02/26/6188e92c7df8a3297.jpg);
			background-size: cover;
			opacity: 0.5;
		}

		.placeorder-takeout {
			background-image: url(https://img2.baidu.com/it/u=3648540380,3101692525&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=325);
			background-size: cover;
		}

		.placeorder-kong-title {
			width: 50%;
			height: 70rpx;
			box-sizing: border-box;
			padding: 30rpx 0 20rpx 26rpx;
			font-size: 32rpx;
			font-weight: bold;
			text-shadow: 2px 2px 2px #CCCCCC;
		}

		.placeorder-kong-content {
			width: 80%;
			height: 50rpx;
			box-sizing: border-box;
			padding: 10rpx 0 20rpx 26rpx;
			font-size: 24rpx;
			color: #777777;
		}
	}

	.bottombanner {
		width: 100%;
		height: 150rpx;
		display: flex;
		justify-content: space-between;
		margin-top: 20rpx;
		margin-bottom: 20rpx;

		.bottombanner-item {
			width: 32%;
			height: 100%;
			background-color: #FFFFFF;
			border-radius: 15rpx;
			box-sizing: border-box;
			text-align: center;
			padding: 10rpx;
			font-weight: bold;
			color: #555555;
		}

		.item1 {
			background-image: url(http://www.itlaobing.com/ice/banner/bottombanner01.png);
			background-repeat: no-repeat;
			background-position: bottom right;
		}

		.item2 {
			background-image: url(http://www.itlaobing.com/ice/banner/bottombanner02.png);
			background-repeat: no-repeat;
			background-position: bottom right;
		}

		.item3 {
			background-image: url(http://www.itlaobing.com/ice/banner/bottombanner03.png);
			background-repeat: no-repeat;
			background-position: bottom right;
		}
	}
</style>
